/*项目工资发放-列表*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:frametrim/route/Routes.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/views/button_round.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../views/MyUnderlineTabIndicator.dart';
import '../../views/appbar_search_toAppbar.dart';
import '../../views/background_view.dart';

class ProjectSalaryIssuePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => ProjectSalaryIssueState();
}

class ProjectSalaryIssueState extends State<ProjectSalaryIssuePage>
    with TickerProviderStateMixin {
  //TickerProviderStateMixin
  TextEditingController _controller = TextEditingController();
  final List<Tab> myTabs = [
    Tab(text: "全部"),
    Tab(text: "已发"),
    Tab(text: "未发"),
    Tab(text: "部分未发"),
  ];
  late TabController _tabController; //需要定义一个Controller
  RefreshController _refreshController =
      RefreshController(initialRefresh: false);

  //项目列表
  List<String> mData = [];

  @override
  void initState() {
    super.initState();
    // 创建Controller
    _tabController = TabController(length: myTabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: SQColor.color_background,
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          leadingWidth: 0,
          titleSpacing: 0,
          title: AppbarSearchUseAppBarTitle(
            imgStr: 'image/imv_back.png',
            controller: _controller,
            callback: (str) {},
            isNeedJump: true,
            isShowSearchImg: false,
          ),
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(40),
            child: Align(
              alignment: Alignment.center,
              child: TabBar(
                tabs: myTabs,
                controller: _tabController,
                // 定义TabWeight,若数量和定义不一致会报错
                onTap: (int index) {
                  print('Selected......$index');
                  /* currentPage = 1;
            getState(index);
            getData("");*/
                },
                //设置未选中时的字体颜色，tabs里面的字体样式优先级最高
                unselectedLabelColor: SQColor.color_90black,
                //设置未选中时的字体样式，tabs里面的字体样式优先级最高
                unselectedLabelStyle: TextStyle(fontSize: 16),
                //设置选中时的字体颜色，tabs里面的字体样式优先级最高
                labelColor: SQColor.color_90black,
                //设置选中时的字体样式，tabs里面的字体样式优先级最高
                labelStyle: TextStyle(fontSize: 16.0),
                //允许左右滚动
                isScrollable: true,
                indicator: MyUnderlineTabIndicator(
                    borderSide:
                        BorderSide(width: 3.0, color: SQColor.color_0052D9)),
              ),
            ),
          ),
        ),
        body: Column(
          children: [
            Divider(height: 1, color: SQColor.color_DEDEDE),
            Expanded(
                child: SmartRefresher(
                    enablePullDown: true,
                    enablePullUp: true,
                    controller: _refreshController,
                    onRefresh: () async {
                      // currentPage = 1;
                      // getData("");
                      Future.delayed(Duration(milliseconds: 2000), () {
                        _refreshController.refreshCompleted();
                      });
                    },
                    onLoading: () async {
                      // currentPage++;
                      // getData("");
                      Future.delayed(Duration(milliseconds: 2000), () {
                        _refreshController.loadComplete();
                        // _refreshController.loadNoData();
                      });
                    },
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemBuilder: (context, index) {
                        return buildItem();
                      },
                      itemCount: 5,
                    )))
          ],
        ));
  }

  Widget buildItem() {
    return GestureDetector(
      onTap: () {
        Get.toNamed(Routes.Project_Salary_Issue_Details);
      },
      child: BackgroundView(
        mVerticalTopMargin: 10,
        mVerticalBottomMargin: 0,
        widget: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                    child: Text('郑州市金水区陈砦城中村改造项目安置区B-04-01地块二标段',
                        style: TextStyle(
                            color: SQColor.color_3D3D3D, fontSize: 16))),
                SizedBox(width: 20),
                Text('待审核',
                    style: TextStyle(fontSize: 14, color: SQColor.color_ED7B2F))
              ],
            ),
            SizedBox(height: 15),
            Text('事件编号：豫788788878787【4567】',
                style: TextStyle(fontSize: 14, color: SQColor.color_60black)),
            SizedBox(height: 8),
            Text('上报时间：2022-03-28  10:30:25',
                style: TextStyle(fontSize: 14, color: SQColor.color_60black)),
            SizedBox(height: 8),
            Text('问题数量：5',
                style: TextStyle(fontSize: 14, color: SQColor.color_60black)),
            SizedBox(height: 8),
            Text('拟扣分数：-25',
                style: TextStyle(fontSize: 14, color: SQColor.color_60black)),
            SizedBox(height: 20),
            Container(
              width: Screen.width - 42,
              height: 40,
              child: ButtonRoundView(
                textStr: '立即审核',
                textColor: SQColor.color_0052D9,
                buttonColor: SQColor.color_ECF2FE,
                onPress: () {
                  Get.toNamed(Routes.Project_Salary_Issue_Details);
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}
